const { exec } = require('child_process');
const fs = require('fs');
const path = require('path');
const makeP = require('../utils/makeProcess');

// install yh-page --registry=http://10.19.126.15:4873/ --force

async function installYhDesign() {
  return makeP(`${/^win/.test(process.platform) ? 'npm.cmd' : 'npm'}`, [
    'install',
    '@yh/yh-design',
    '--registry=http://10.19.126.15:4873/',
    '--force',
  ]);
}

const checkYhDesign = () => {
  const packagePath = path.join(global.cwdPath, './node_modules');
  const isExsit = fs.existsSync(path.join(packagePath, '@yh/yh-design'));
  if (isExsit) return Promise.resolve(1);

  global.log.warn('Your node_modules package dont have yh-design');
  return installYhDesign();
};

module.exports = checkYhDesign;
